use ::libc;
extern "C" {
    pub type args;
    pub type cmd;
    pub type cmdq_item;
    fn free(_: *mut libc::c_void);
    fn args_get(_: *mut args, _: u_char) -> *const libc::c_char;
    fn cmd_get_entry(_: *mut cmd) -> *const cmd_entry;
    fn cmd_get_args(_: *mut cmd) -> *mut args;
    fn cmdq_print(_: *mut cmdq_item, _: *const libc::c_char, _: ...);
    fn cmdq_error(_: *mut cmdq_item, _: *const libc::c_char, _: ...);
    static mut status_prompt_hlist: [*mut *mut libc::c_char; 0];
    static mut status_prompt_hsize: [u_int; 0];
    fn status_prompt_type_string(_: u_int) -> *const libc::c_char;
    fn status_prompt_type(type_0: *const libc::c_char) -> prompt_type;
}
pub type __u_char = libc::c_uchar;
pub type __u_int = libc::c_uint;
pub type u_char = __u_char;
pub type u_int = __u_int;
pub type prompt_type = libc::c_uint;
pub const PROMPT_TYPE_INVALID: prompt_type = 255;
pub const PROMPT_TYPE_WINDOW_TARGET: prompt_type = 3;
pub const PROMPT_TYPE_TARGET: prompt_type = 2;
pub const PROMPT_TYPE_SEARCH: prompt_type = 1;
pub const PROMPT_TYPE_COMMAND: prompt_type = 0;
pub type args_parse_type = libc::c_uint;
pub const ARGS_PARSE_COMMANDS: args_parse_type = 3;
pub const ARGS_PARSE_COMMANDS_OR_STRING: args_parse_type = 2;
pub const ARGS_PARSE_STRING: args_parse_type = 1;
pub const ARGS_PARSE_INVALID: args_parse_type = 0;
pub type args_parse_cb =
    Option<unsafe extern "C" fn(*mut args, u_int, *mut *mut libc::c_char) -> args_parse_type>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct args_parse {
    pub template: *const libc::c_char,
    pub lower: libc::c_int,
    pub upper: libc::c_int,
    pub cb: args_parse_cb,
}
pub type cmd_find_type = libc::c_uint;
pub const CMD_FIND_SESSION: cmd_find_type = 2;
pub const CMD_FIND_WINDOW: cmd_find_type = 1;
pub const CMD_FIND_PANE: cmd_find_type = 0;
pub type cmd_retval = libc::c_int;
pub const CMD_RETURN_STOP: cmd_retval = 2;
pub const CMD_RETURN_WAIT: cmd_retval = 1;
pub const CMD_RETURN_NORMAL: cmd_retval = 0;
pub const CMD_RETURN_ERROR: cmd_retval = -1;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry_flag {
    pub flag: libc::c_char,
    pub type_0: cmd_find_type,
    pub flags: libc::c_int,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct cmd_entry {
    pub name: *const libc::c_char,
    pub alias: *const libc::c_char,
    pub args: args_parse,
    pub usage: *const libc::c_char,
    pub source: cmd_entry_flag,
    pub target: cmd_entry_flag,
    pub flags: libc::c_int,
    pub exec: Option<unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval>,
}
#[no_mangle]
pub static mut cmd_show_prompt_history_entry: cmd_entry = unsafe {
    {
        let mut init = cmd_entry {
            name: b"show-prompt-history\0" as *const u8 as *const libc::c_char,
            alias: b"showphist\0" as *const u8 as *const libc::c_char,
            args: {
                let mut init = args_parse {
                    template: b"T:\0" as *const u8 as *const libc::c_char,
                    lower: 0 as libc::c_int,
                    upper: 0 as libc::c_int,
                    cb: None,
                };
                init
            },
            usage: b"[-T type]\0" as *const u8 as *const libc::c_char,
            source: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            target: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            flags: 0x4 as libc::c_int,
            exec: Some(
                cmd_show_prompt_history_exec
                    as unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval,
            ),
        };
        init
    }
};
#[no_mangle]
pub static mut cmd_clear_prompt_history_entry: cmd_entry = unsafe {
    {
        let mut init = cmd_entry {
            name: b"clear-prompt-history\0" as *const u8 as *const libc::c_char,
            alias: b"clearphist\0" as *const u8 as *const libc::c_char,
            args: {
                let mut init = args_parse {
                    template: b"T:\0" as *const u8 as *const libc::c_char,
                    lower: 0 as libc::c_int,
                    upper: 0 as libc::c_int,
                    cb: None,
                };
                init
            },
            usage: b"[-T type]\0" as *const u8 as *const libc::c_char,
            source: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            target: cmd_entry_flag {
                flag: 0,
                type_0: CMD_FIND_PANE,
                flags: 0,
            },
            flags: 0x4 as libc::c_int,
            exec: Some(
                cmd_show_prompt_history_exec
                    as unsafe extern "C" fn(*mut cmd, *mut cmdq_item) -> cmd_retval,
            ),
        };
        init
    }
};
unsafe extern "C" fn cmd_show_prompt_history_exec(
    mut self_0: *mut cmd,
    mut item: *mut cmdq_item,
) -> cmd_retval {
    let mut args: *mut args = cmd_get_args(self_0);
    let mut typestr: *const libc::c_char = args_get(args, 'T' as i32 as u_char);
    let mut type_0: prompt_type = PROMPT_TYPE_COMMAND;
    let mut tidx: u_int = 0;
    let mut hidx: u_int = 0;
    if cmd_get_entry(self_0) == &cmd_clear_prompt_history_entry as *const cmd_entry {
        if typestr.is_null() {
            tidx = 0 as libc::c_int as u_int;
            while tidx < 4 as libc::c_int as libc::c_uint {
                free(*status_prompt_hlist.as_mut_ptr().offset(tidx as isize) as *mut libc::c_void);
                let fresh0 = &mut (*status_prompt_hlist.as_mut_ptr().offset(tidx as isize));
                *fresh0 = std::ptr::null_mut::<*mut libc::c_char>();
                *status_prompt_hsize.as_mut_ptr().offset(tidx as isize) = 0 as libc::c_int as u_int;
                tidx = tidx.wrapping_add(1);
            }
        } else {
            type_0 = status_prompt_type(typestr);
            if type_0 as libc::c_uint == PROMPT_TYPE_INVALID as libc::c_int as libc::c_uint {
                cmdq_error(
                    item,
                    b"invalid type: %s\0" as *const u8 as *const libc::c_char,
                    typestr,
                );
                return CMD_RETURN_ERROR;
            }
            free(*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize) as *mut libc::c_void);
            let fresh1 = &mut (*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize));
            *fresh1 = std::ptr::null_mut::<*mut libc::c_char>();
            *status_prompt_hsize.as_mut_ptr().offset(type_0 as isize) = 0 as libc::c_int as u_int;
        }
        return CMD_RETURN_NORMAL;
    }
    if typestr.is_null() {
        tidx = 0 as libc::c_int as u_int;
        while tidx < 4 as libc::c_int as libc::c_uint {
            cmdq_print(
                item,
                b"History for %s:\n\0" as *const u8 as *const libc::c_char,
                status_prompt_type_string(tidx),
            );
            hidx = 0 as libc::c_int as u_int;
            while hidx < *status_prompt_hsize.as_mut_ptr().offset(tidx as isize) {
                cmdq_print(
                    item,
                    b"%d: %s\0" as *const u8 as *const libc::c_char,
                    hidx.wrapping_add(1 as libc::c_int as libc::c_uint),
                    *(*status_prompt_hlist.as_mut_ptr().offset(tidx as isize))
                        .offset(hidx as isize),
                );
                hidx = hidx.wrapping_add(1);
            }
            cmdq_print(
                item,
                b"%s\0" as *const u8 as *const libc::c_char,
                b"\0" as *const u8 as *const libc::c_char,
            );
            tidx = tidx.wrapping_add(1);
        }
    } else {
        type_0 = status_prompt_type(typestr);
        if type_0 as libc::c_uint == PROMPT_TYPE_INVALID as libc::c_int as libc::c_uint {
            cmdq_error(
                item,
                b"invalid type: %s\0" as *const u8 as *const libc::c_char,
                typestr,
            );
            return CMD_RETURN_ERROR;
        }
        cmdq_print(
            item,
            b"History for %s:\n\0" as *const u8 as *const libc::c_char,
            status_prompt_type_string(type_0 as u_int),
        );
        hidx = 0 as libc::c_int as u_int;
        while hidx < *status_prompt_hsize.as_mut_ptr().offset(type_0 as isize) {
            cmdq_print(
                item,
                b"%d: %s\0" as *const u8 as *const libc::c_char,
                hidx.wrapping_add(1 as libc::c_int as libc::c_uint),
                *(*status_prompt_hlist.as_mut_ptr().offset(type_0 as isize)).offset(hidx as isize),
            );
            hidx = hidx.wrapping_add(1);
        }
        cmdq_print(
            item,
            b"%s\0" as *const u8 as *const libc::c_char,
            b"\0" as *const u8 as *const libc::c_char,
        );
    }
    return CMD_RETURN_NORMAL;
}
